﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using OABLL;
using OAModel;

namespace MyOA
{
    public partial class ZhuanZhengXinXi : Form
    {
        ZhuanZhengBLL bll = new ZhuanZhengBLL();
        public string _yuangongid = string.Empty;

        
        public ZhuanZhengXinXi(string oa)
        {
            InitializeComponent();
            this._yuangongid = oa;
           
        }

     

        private void btn转正提交_Click(object sender, EventArgs e)
        {
            Random rd = new Random();
            ZhuanzhengEntity zz = new ZhuanzhengEntity();
            zz.Oa员工id = lbl员工id.Text;
            zz.Oa申请号 = rd.Next(10000, 9999999).ToString();
            zz.Oa转正内容 = tx转正内容.Text.Trim();
            zz.Oa员工姓名 = label4.Text;
          
            bool bl = bll.Addzhuanzheng(zz);
            if (bl == true)
            {
                MessageBox.Show("提交申请成功，等待审批中！");

            }
            else
            {
                MessageBox.Show("提交申请失败，请稍后重试！");
            }

 
            List<ZhuanzhengEntity> list = new List<ZhuanzhengEntity>();
            list = bll.Addnewzhuanzheng(_yuangongid);
            listView1.Items.Clear();
            for (int i = 0; i < list.Count; i++)
            {
                ZhuanzhengEntity user = list[i];
                ListViewItem item = new ListViewItem();
                item.Text = user.Oa员工id;
                item.SubItems.Add(user.Oa员工姓名);
               
                item.SubItems.Add(user.Oa转正内容);
                 item.SubItems.Add(user.Oa申请号);
                 item.SubItems.Add(user.Oa时间);
                string str = "";
                if (user.Oa状态.ToString() == "0")
                {

                    str = "待审核";
                }
                else if (user.Oa状态.ToString() == "1")
                {
                    str = "审核通过";
                }
                else
                {
                    str = "审核不通过";
                }

                item.SubItems.Add(str);

                this.listView1.Items.Add(item);
            }

            


        }

        private void 查看申请ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string Oa申请号 = this.listView1.SelectedItems[0].SubItems[3].Text.Trim();
            new ChaKanZhuanZheng(_yuangongid,Oa申请号).ShowDialog();
        }

        private void lk转正提交_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string key = this.lbl员工id.Text.Trim();
            List<ZhuanzhengEntity> list = bll.Getneirong(key);
            this.listView1.Items.Clear();
            for (int i = 0; i<list.Count;i++) 
            {
                ZhuanzhengEntity user = list[i];

                ListViewItem item = new ListViewItem();
                item.Text = user.Oa员工id;
                item.SubItems.Add(user.Oa员工姓名);
                item.SubItems.Add(user.Oa转正内容);
                item.SubItems.Add(user.Oa申请号);
                item.SubItems.Add(user.Oa时间);
                string str = "";
                if (user.Oa状态.ToString() == "0")
                {

                    str = "待审核";
                }
                else if (user.Oa状态.ToString() == "1")
                {
                    str = "审核通过";
                }
                else
                {
                    str = "审核不通过";
                }

                item.SubItems.Add(str);
                this.listView1.Items.Add(item);
            }

           

        }

        private void 修改申请ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string Oa申请号 = this.listView1.SelectedItems[0].SubItems[3].Text.Trim();
            new ChaKanZhuanZheng(_yuangongid, Oa申请号).Show();

        }

        private void ZhuanZhengXinXi_Load(object sender, EventArgs e)
        {
            OAUseEntity user = new OAUseBLL().Getyuangong(_yuangongid);
            this.lbl员工id.Text = user.Oa员工id;
            this.label4.Text = user.Oa姓名;
        }

        private void 删除申请ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {



                string Oa申请号 = this.listView1.SelectedItems[0].SubItems[3].Text.Trim();

                if (bll.Dropshengqi(Oa申请号))
                {

                    foreach (ListViewItem item in this.listView1.SelectedItems)
                    {
                        this.listView1.Items.RemoveAt(item.Index);
                    }
                }
                else
                {
                    MessageBox.Show("删除失败，请稍后重试！");
                }




            }
        }
    }
}
